package com.ruoyi.scene.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.scene.domain.SceneInspectionIssue;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.scene.domain.vo.SceneInspectionIssueVo;
import com.ruoyi.scene.domain.bo.SceneInspectionIssueBo;
import com.ruoyi.scene.service.ISceneInspectionIssueService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 现场巡查问题
 *
 * @author llb
 * @date 2024-10-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/scene/inspectionIssue")
public class SceneInspectionIssueController extends BaseController {

    private final ISceneInspectionIssueService iSceneInspectionIssueService;

    /**
     * 查询现场巡查问题列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<SceneInspectionIssueVo> list(SceneInspectionIssueBo bo, PageQuery pageQuery) {
        return iSceneInspectionIssueService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出现场巡查问题列表
     */
    @SaCheckLogin
    @Log(title = "现场巡查问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SceneInspectionIssueBo bo, HttpServletResponse response) {
        List<SceneInspectionIssueVo> list = iSceneInspectionIssueService.queryList(bo);
        ExcelUtil.exportExcel(list, "现场巡查问题", SceneInspectionIssueVo.class, response);
    }

    /**
     * 获取现场巡查问题详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<SceneInspectionIssueVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iSceneInspectionIssueService.queryById(id));
    }

    /**
     * 新增现场巡查问题
     */
    @SaCheckLogin
    @Log(title = "现场巡查问题", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SceneInspectionIssueBo bo) {
        return toAjax(iSceneInspectionIssueService.insertByBo(bo));
    }

    /**
     * 修改现场巡查问题
     */
    @SaCheckLogin
    @Log(title = "现场巡查问题", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SceneInspectionIssueBo bo) {
        return toAjax(iSceneInspectionIssueService.updateByBo(bo));
    }

    /**
     * 删除现场巡查问题
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @Log(title = "现场巡查问题", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iSceneInspectionIssueService.deleteWithValidByIds(Arrays.asList(ids), true));
    }


    /**
     * 提交修改状态
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/submit")
    public R<Void> submit(Long id) {
        SceneInspectionIssueBo bo = new SceneInspectionIssueBo();
        bo.setId(id);
        bo.setApprovalStatus("11");
        return toAjax(iSceneInspectionIssueService.submit(bo));
    }
}
